package com.example.androidpractice.viewmodel;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Transformations;
import androidx.lifecycle.ViewModel;

import com.example.androidpractice.model.Task;
import com.example.androidpractice.reposity.TaskResposity;

import java.util.List;

public class TasksViewModel extends ViewModel {
    MutableLiveData<String> catalog=new MutableLiveData<>();
    LiveData<List<Task>> tasks;
    TaskResposity taskResposity=new TaskResposity();
    public  TasksViewModel(){
        tasks= Transformations.switchMap(catalog,catalog->{
            MutableLiveData<List<Task>> temp=  new MutableLiveData<List<Task>>();
            if (catalog!=null && catalog.length()>0) {
                temp.setValue(taskResposity.getTaskByCatalog(catalog));
            }
            return temp;
        });
    }

    public  void setCatalog(String catalog){
        this.catalog.setValue(catalog);
    }

}
